﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.Xpo;

namespace Component
{
    public class ProductDB:Base
    {
        public static XPCollection<Product> GetAll(bool admin)
        {
            XPCollection<Product> _xpProduct = new XPCollection<Product>(KetNoiCSDL.session);            
            _xpProduct.Filter = FilterAll(admin);
            _xpProduct.Sorting = SetupSort(ColumProduct._Priority, true);
          
            return _xpProduct;
        }

        public static Product GetObjById(int id,bool admin)
        {
            XPCollection<Product> _xpProduct = new XPCollection<Product>(KetNoiCSDL.session);
            _xpProduct.Filter = FilterById(id);
            if (_xpProduct.Count > 0)
            {
                return _xpProduct[0];
            }
            return null;
            
        }
        public static XPCollection<Product> GetAllProduct(bool admin)
        {
            XPCollection<Product> _xpProducts = new XPCollection<Product>(KetNoiCSDL.session);
            if (admin == false)
            {
                _xpProducts.Filter = DevExpress.Data.Filtering.CriteriaOperator.Parse(ColumProduct._Active + ConstString._dauBangVaAnd + ColumProduct._New + ConstString._dauBang, true, true);
            }
            else
                _xpProducts.Filter = DevExpress.Data.Filtering.CriteriaOperator.Parse(ColumProduct._New + ConstString._dauBang, true);
            _xpProducts.Sorting = SetupSort(ColumProduct._SubCat, false);
            return _xpProducts;
        }
    }
}
